package com.saic.data.dotask;

import it.sauronsoftware.ftp4j.FTPFile;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Result;

import com.saic.data.table.TableAction;
import com.saic.data.table.TableUtil;
import com.saic.data.util.HbaseUtil;

/**
 * @Update check time
 * @author Xinshiyou
 */
public class UpdateCheckTime extends DoTask {

	private String tabName;
	private FTPFile f;
	private Result res;

	public UpdateCheckTime(String tabName, Result res, FTPFile f) {
		super();
		this.tabName = tabName;
		this.res = res;
		this.f = f;
	}

	@Override
	public void doTask() {
		try {
			boolean flag;
			flag = HbaseUtil.updateData(tabName, res.getRow(),
					TableUtil.configtabFamily,"fileSize", f.getSize() + "");
			TableUtil.pm(this.getClass(), "Update " + tabName + ":fileSize "
					+ (flag ? "SUCCESS" : "FAILER"));
			flag = HbaseUtil.updateData(tabName, res.getRow(), 
					TableUtil.configtabFamily,"checkTime",System.currentTimeMillis() + "");
			TableUtil.pm(this.getClass(), "Update " + tabName + ":checkTime "
					+ (flag ? "SUCCESS" : "FAILER"));
			flag = HbaseUtil.updateData(tabName, res.getRow(), 
					TableUtil.configtabFamily,"fileStats", TableAction.Wait.toString());
			TableUtil.pm(this.getClass(), "Update " + tabName + ":fileStats "
					+ (flag ? "SUCCESS" : "FAILER"));
			flag = HbaseUtil.updateData(tabName, res.getRow(), 
					TableUtil.configtabFamily,"modifiedDate", TableUtil.formatDate(f.getModifiedDate()));
			TableUtil.pm(this.getClass(), "Update " + tabName + ":modifiedDate "
					+ (flag ? "SUCCESS" : "FAILER"));
			
		} catch (IOException e) {
			TableUtil.pm(this.getClass(), e.getMessage());
		}
	}

	@Override
	public Object getResult() {
		return result;
	}
}